import platform;
import os;
import glob;

def make_environ_vars():
	"""Returns a dictionnary with environment variable to use when compiling."""
	# PATH is required to find the compiler
	# TEMP is required for at least mingw
	vars = {}
	for name in ('PATH', 'TEMP', 'TMP'):
		if name in os.environ:
			vars[name] = os.environ[name]
	return vars

def listFiles(files):
	allFiles = []
	for file in files:
		if file.find('*') == -1:
			allFiles.append(file)
		else:
			newFiles = glob.glob(os.path.join(str(Dir('.').srcnode()),file))
			for newFile in newFiles:
				newFile = str(Dir('.').srcnode().rel_path(File(newFile)))
				allFiles.append(newFile)
	return allFiles

baseEnv = Environment( ENV = make_environ_vars(),
	toolpath = ['scons-tools'], CPPPATH = ["src"],
	tools=[] ) #, tools=['default'] )

baseEnv.Tool( 'default' )
baseEnv.Append( LIBS = ['nymphaea', 'pthread', 'cppunit', 'json', 'cppunit', 'gsl', 'gslcblas'], LIBPATH = '.', CCFLAGS = "-ggdb -Wall" , CPPDEFINES = ['DEBUG',])
baseEnv['SHARED_LIB_ENABLED'] = True


progEnv = baseEnv.Clone();
libEnv = baseEnv.Clone();

source_dir = "src";
lib_modules = ["comm", "matrices", "learner", "sample"];

lib_files = map(lambda x: source_dir + "/" + x + "/*.cpp", lib_modules);

nymphaeaLib = libEnv.StaticLibrary('nymphaea', listFiles(lib_files));

testBin = progEnv.Program('unittest', ['test/unit.cpp', 'test/matrix_test.h', 'test/matrix_test.cpp', 'test/nymphaea_test.cpp'])

#progEnv.Tool('registerObjects', package = 'nymphaea', libraries = [nymphaeaLib], includes = [], binaries = [testBin]);
